home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1988 / 05 / logoff.rex < prev    next >
OS/2 REXX Batch file  |  1988-08-18  |  9KB  |  247 lines

  1. /* Copyright Andrew J. Chalk, 1987, 1988.  All Rights Reserved.               */
  2. /* Purpose: A utility to create and maintain a log computer usage             */
  3. /* Usage: i)   Install RXINTMGR, STACKMGR, RXBATMGR,                          */
  4. /*             ANSI.SYS and GLOBALV.                                          */
  5. /*        ii)  Ensure EXECIO.EXE is in your path when LOGOFF is called.       */
  6. /*        iii) Place the command "Logoff on" in your autoexec.bat             */
  7. /*        iv)  When you finish work, type "logoff"                            */
  8. /* REXXLOG will create a file called USAGE.LOG as specified below             */
  9. /* This file contains a record of your computer usage.                        */
  10. /* First version 5/15/87. Last update: 05-11-88.                              */
  11.  
  12. trace n
  13. options newcom
  14.  
  15. /********************* VARIABLES GLOBAL TO THE PROGRAM ************************/
  16. /* USERS: This is where you record the name of your logfile */
  17. logfile = 'c:\rexx\myrexx\usage.log'            /* location of log */
  18. ver = 'Version 1.2'                             /* program version number */
  19.  
  20. /******************************************************************************/
  21.  
  22. arg status .                           /* are we logging on or off?   */
  23.   'cls'
  24.   call intro                           /* Show the intro screen       */
  25.   select
  26.     when status = on then call logon   /* You want to logon..         */
  27.     when status = '' then call logoff  /* You want to logoff..        */
  28.     otherwise call error 1
  29.   end
  30.   call total_time                      /* Let's find out how long     */
  31.   if dosdir('c:\lasting.bak') <> '' then call dosdel 'c:\lasting.bak'
  32. exit(0)
  33.  
  34.  
  35. /* THIS PROCEDURE PUTS AN INTRODUCTORY HEADER ON THE SCREEN */
  36. intro : procedure expose ver
  37.  
  38.   h1 = 'REXXLOG -- THE REXX COMPUTER USAGE LOG'
  39.   cpyrt = right('(C) Andrew J. Chalk, 1987,1988. All Rights Reserved',80)
  40.   h2 = overlay(ver,cpyrt)
  41.   say Centre('' h1 '',96)
  42.   say h2
  43. return
  44.  
  45.  
  46. check_file : procedure expose logfile ver       /*  create a new log?  */
  47.  
  48.   if dosdir(logfile) <> '' then call check_date
  49.   if result = 1 then return
  50.   h1 = Center('REXXLOG -- THE REXX COMPUTER USAGE LOG',80)
  51.   cpyrt = right('Copyright Andrew J. Chalk, 1987. All Rights Reserved.',80)
  52.   h2 = overlay(ver,cpyrt)                      /* what an egotist! */
  53.   t1 = left('Date',80)
  54.   d1 = 'On Time'
  55.   t1 = overlay(d1,t1,23)
  56.   d2 = 'Off Time'
  57.   t1 = overlay(d2,t1,32)
  58.   d3 = 'Purpose of work'
  59.   t1 = overlay(d3,t1,41)
  60.   d4 = 'Time On'
  61.   h3 = overlay(d4,t1,73)
  62.   call lineout logfile, h1
  63.   call lineout logfile, h2
  64.   call lineout logfile, ' '
  65.   call lineout logfile, h3
  66.   call lineout logfile
  67.   say Centre(' File' logfile 'not found. New Logfile Created. ',95)
  68.  
  69. return
  70.  
  71.  
  72. check_date:procedure expose logfile       /* Has the month changed?   */
  73.                                           /* If so, create an archive */
  74.     file_month = substr(dosdir(logfile,d),1,2) /* the month of the logfile */
  75.     actual_month = substr(date('U'),1,2)       /* the month at runtime */
  76.     if actual_month = file_month then return 1
  77.     fpath = substr(logfile,1,lastpos('\',logfile))
  78.     fspec = dosdir(logfile,n)
  79.     if pos('.',fspec) <> '' then fname = substr(fspec,1,pos('.',fspec)-1)
  80.     else fname = fspec
  81.  
  82.     /* HOW TO USE SETS IN REXX */
  83.     monthset = jan feb mar apr may jun jul aug sep oct nov dec
  84.     month = word(monthset,file_month)
  85.     'copy' logfile fpath||fname'.'month '> nul'
  86.     'erase' logfile
  87. return 0
  88.  
  89.  
  90. logon : procedure expose logfile       /* logon procedure */
  91.  
  92.     call check_file    /* if logfile does not exist then create a new one */
  93.     if dosdir('c:\lasting.glv') <> '' then return
  94.     reason = purpose()
  95.     day = left(date('w'),9)
  96.     fdate = right(date(),11)
  97.     info = day fdate'. On at' time()
  98.     'globalv select worklog setpl instring1' info
  99.     info = day fdate'. On at' time() 'to work on' reason
  100.     'globalv select worklog setpl instring2' reason
  101.     say Centre(' The Following Logon Information was Recorded by REXXLOG ',95)
  102.     say Centre('' info ' ',88)
  103.  
  104. return
  105.  
  106.  
  107. purpose: procedure
  108.  
  109.     say 'Enter purpose of logging on (for tax records):'
  110.     say
  111.     parse pull reason
  112.     reason = strip(substr(reason,1,80),t)
  113.  
  114. return reason
  115.  
  116.  
  117. logoff : procedure expose logfile
  118.  
  119.     call check_file
  120.     if dosdir('c:\lasting.glv') = '' then return  /* already logged off! */
  121.     'globalv select worklog get instring1'
  122.     intime  = word(instring1,words(instring1))
  123.     outtime = time()
  124.     time_on = elapsed_time(intime,outtime)
  125.     'globalv select worklog get instring2'
  126.     temp1 = left(word(instring1,1),9)    /* the day */
  127.     temp2 = left(word(instring1,2),2)    /* the date */
  128.     temp3 = left(word(instring1,3),3)    /* the month */
  129.     temp4 = left(word(instring1,4),4)    /* the year */
  130.     temp5 = left(intime,8)
  131.     temp6 = left(outtime,8)
  132.     temp7 = left(instring2,31)
  133.     temp8 = left(time_on,8)
  134.     b3 = ''
  135.     outinfo1 = temp1 temp2 temp3 temp4 temp5 temp6 temp7 temp8
  136.     outinfo2 = instring1'. Off at' outtime'. Time on:' time_on
  137.     outinfo3 = 'Work:' instring2
  138.     call lineout logfile, outinfo1
  139.     if result <> 0 then call error result
  140.     call lineout logfile
  141.     say Centre(' The Following Logoff Information was Recorded by REXXLOG ',95)
  142.     say Centre('' outinfo2 '',88)
  143.     say Centre('' outinfo3 '',94)
  144.     if dosdir('c:\lasting.glv') <> '' then 'erase c:\lasting.glv'
  145.  
  146. return
  147.  
  148.  
  149. elapsed_time:procedure                      /* How long were we on? */
  150. arg start, finish
  151. ehours = 0;emins=0;
  152.  
  153.     shour = substr(start,1,pos(':',start)-1)
  154.     smin = substr(start,pos(':',start)+1,2)
  155.     ssec = substr(start,7,2)
  156.     fhour = substr(finish,1,pos(':',finish)-1)
  157.     fmin = substr(finish,pos(':',finish)+1,2)
  158.     fsec = substr(finish,7,2)
  159.  
  160.     start_secs = (shour*3600) + (smin*60) + ssec
  161.     finish_secs = (fhour*3600) + (fmin*60) + fsec
  162.  
  163.     esecs = finish_secs - start_secs
  164.     if esecs < 0 then esecs = esecs + 86400     /* midnight passed */
  165.     if esecs > 3600 then do
  166.         ehours = esecs % 3600
  167.         esecs = esecs // 3600
  168.     end
  169.     if esecs > 60 then do
  170.         emins = esecs % 60
  171.         esecs = esecs // 60
  172.     end
  173.     if ehours < 10 then ehours = '0'ehours;
  174.     if emins < 10 then emins = '0'emins
  175.     if esecs < 10 then esecs = '0'esecs
  176.     etime = ehours':'emins':'esecs
  177.  
  178. return etime
  179.  
  180.  
  181. total_time:procedure expose logfile /* How long were we on this MONTH!*/
  182.  
  183.     thours = 0;tmins=0; tsecs=0;
  184.  
  185.     stack_state = stackstatus()          /* is the stack installed and large enough? */
  186.     parse var stack_state flag id free
  187.     if flag = n | flag = d then call error 3 /* stack not installed */
  188.     filesize = word(dosdir(logfile),2)
  189.     if filesize >= free then call error 4
  190.     theirs = queued()
  191.  
  192.  
  193.     address command 'execio * diskr' logfile '0 (fifo finis notype'
  194.     if rc < 0 | rc = 28 then call error rc
  195.     do 4                                 /* pull header */
  196.         pull
  197.     end
  198.  
  199.     do while queued() > theirs
  200.         pull line
  201.         time = word(line,words(line))      /* the time on is the last line */
  202.         shour = substr(time,1,pos(':',time)-1)
  203.         smin = substr(time,pos(':',time)+1,2)
  204.         ssec = substr(time,7,2)
  205.         secs = (shour*3600) + (smin*60) + ssec
  206.         tsecs = secs + tsecs
  207.     end
  208.     if tsecs > 3600 then do
  209.         thours = tsecs % 3600
  210.         tsecs = tsecs // 3600
  211.     end
  212.     if tsecs > 60 then do
  213.         tmins = tsecs % 60
  214.         tsecs = tsecs // 60
  215.     end
  216.     if thours < 10 then thours = '0'thours
  217.     if tmins < 10 then tmins = '0'tmins
  218.     if tsecs < 10 then tsecs = '0'tsecs
  219.     ttime = thours':'tmins':'tsecs
  220.     say Centre(' Total Time On This Month is' ttime' ',94)
  221.  
  222. return ttime
  223.  
  224.  
  225. error: procedure                            /* Errors happen! */
  226. arg enum
  227.  
  228. select
  229.     when enum = -8 then,
  230.       say ' Error:  Insufficient REXX storage run command.'
  231.     when enum = -3 then,
  232.       say ' Error:  Requested program could not be found. '
  233.     when enum = 1 then,
  234.       say ' Error:  Incorrect syntax. '
  235.     when enum = 2 then,
  236.       say ' Error:  Could not write line to'upper(logfile)||'. '
  237.     when enum = 3 then do
  238.       say ' Error:  Stack manager disabled or not installed. '
  239.       exit(-1)
  240.     end
  241.     when enum = 4 then,
  242.       say ' Error:  Insufficient REXX stack space. '
  243.     otherwise say ' Error:  Unidentified error. '
  244. end
  245. call lineout logfile
  246. exit(1)
  247.